<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
       	<%@ page import="servlets.category.*"%>
<%@ page import="org.hibernate.SessionFactory"%>
<%@ page import="org.hibernate.Session"%>
<%@ page import="java.util.List"%>
<%@ page import="hibernate.model.*"%>
<%@ page import="hibernate.util.HibernateUtil"%>
<%@ page import="hibernate.method.*"%>
<%@ page import="hibernate.method.CategoryMethods"%>
<%@page import="java.util.ArrayList"%>
<% 
String idGry=request.getParameter("game_id");
int game_id = Integer.parseInt(idGry);
%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<link rel="stylesheet" href="css/sidebar.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"> </script>
<style type="text/css">
.templatemo_form input {
	height: 20px;
}
</style>
<div id="games">

<div class="page-header">
	<h2 class="page-title">Edytuj grę</h2>
</div>

<br />

<div id="content">
<% SessionFactory sessionFactory = HibernateUtil
.getSessionAnnotationFactory();
Session s = sessionFactory.openSession();
s.beginTransaction();	
GameMethods gamem = new GameMethods();
Game g =gamem.idToGame(sessionFactory, s, game_id);
CategoryMethods catm = new CategoryMethods(); %>


 
	<form role="form" style="position: block; top: -40px;" id='addGame' enctype="multipart/form-data"
		action="../editGame"  method="POST">
<input type="hidden" id="game_id" name="game_id" value="<%=game_id%>"/>
		<table>
			<tr>
				<td>Nazwa gry:</td>
				<td>
						<%=g.getName() %>
					
				</td>
			</tr>
	
			<tr>
				<td>Minimalna ilosc osób:</td>
				<td>
						<input type="number" id="users_min" name="users_min"
							class="form-control" 
							placeholder="<%=g.getUsers_min() %>" value="<%=g.getUsers_min()%>" maxlength="80">
					
				</td>

			</tr>
			
				<tr>
				<td>Maksymalna ilosc osób:</td>
				<td>
						<input type="number" id="users_max" name="users_max"
							class="form-control" 
							placeholder="<%=g.getUsers_max()%>" value="<%=g.getUsers_max()%>" maxlength="80">
					
				</td>

			</tr>
			
			<tr>
			<td>
			Opis gry
			</td>
			<td>
						<textarea name="description" rows="10" class="form-control" id="description"  placeholder="<%=g.getDescribe()%>"><%=g.getDescribe()%></textarea>
					
			</td>
			</tr>
			

			<tr>
				<td>Avatar:</td>
				<td>
						<input type="file" name="avatar" id="avatar">
						</td>
						<td> 
					<img src="../social/games/gameAvatar.jsp?game_id=<%=game_id%>" alt="GameAvatar" style="height: 115px">
				<br> Aktualny obraz gry 
				</td>
			</tr>
			
			<tr>
			<td> Kategorie do ktorych ma przynalezyc gra: 
			</td>
			<td>
			<%
			GameCategoryMethods gcat = new GameCategoryMethods();
			List<String> gamecategories = new ArrayList<String>();
			gamecategories = gcat.listCategoriesByGame(sessionFactory, s, game_id);
						List <Category> cat = catm.listAllCategories(sessionFactory, s);
							if (cat.size() > 0) {
							for (Category c : cat) {
								
								if (gamecategories.size() >0) {
									String catname = c.getCategory();
									int id = c.getCategory_id();
									//for (String gc : gamecategories){
								
								%>
								
						<input type="checkbox" name="categories" value="<%=id%>" <%if(gamecategories.contains(catname)){%>checked<%} %>/><%=catname%> <br>
						<%
							
					//	}
													}
													}
							}
						if (cat.size() == 0) {
					 out.println("Nie ma zadnych kategorii w bazie");
					
						} %>
			
			
			
			<tr>
				<td><input type="submit" class="mainBtn" value="Dodaj grę" /></td>
			</tr>
		</table>
		
	</form>

	</div>
	</div>